package JavaClass.demo02;

public class Employee {
    /**
     * 编号，姓名，年龄，工资，身份证号码，员工人数，员工工资总额
     */
    private int nums;
    private String name;
    private int age;
    private double salary;
    private String id;
    private static int totalEmployees;
    private static double totalSalary;

    /**
     * 构造器1：设置编号，年龄，姓名；如果年龄小于18，抛出年龄低异常；
     * 如果年龄大于60抛出年龄高异常，如果姓名为null或为空字符串，抛出空异常。
     */

    public Employee(int nums,int age,String name) throws AgeLowException,AgeHighException,EmptyException{
        if(age<18){
            throw new AgeLowException("年龄小于18，抛出年龄低异常");
        }
        if(age>60){
            throw new AgeHighException("年龄大于60，抛出年龄高异常");
        }
        if(name==null||name.isEmpty()){
            throw new EmptyException("姓名为null或为空字符串，抛出空异常");
        }
        this.nums = nums;
        this.age = age;
        this.name = name;
        totalEmployees++;
    }
    /**
     * 设置工资，设置身份证号码；如果工资低于600，抛出工资低异常。
     */
    public void setSalaryAndId(double salary,String id) throws SalaryLowException{
        if (salary<600){
            throw new SalaryLowException("工资低于600，抛出工资低异常");
        }
        this.salary = salary;
        this.id = id;
        totalSalary += salary;
    }
    /**
     * 增加工资 addSalary(double addSalary)，抛出工资高异常，当增加后的工资大于员工工资总额时，抛出此异常。
     */
    public void addSalary(double addSalary) throws SalaryHighException{
        if(this.salary+addSalary > totalSalary){
            throw new SalaryHighException("增加后的工资大于员工工资总额，抛出工资高异常");
        }
        this.salary += addSalary;
        totalSalary += addSalary;
    }
    /**
     * 减少工资 minusSalary(double minusSalary), 抛出工资低异常，当减少后的工资低于政府最低工资时，抛出工资低异常。
     */
    public void minusSalary(double minusSalary) throws SalaryLowException{
        if(this.salary-minusSalary < 600){
            throw new SalaryLowException("减少后的工资低于政府最低工资时，抛出工资低异常");
        }
        this.salary -= minusSalary;
        totalSalary -= minusSalary;
    }
    /**
     * 显示员工工资总额方法：showTotalSalary(), 抛出空异常，当工资总额为0时，抛出此异常。
     */
    public static void showTotalSalary() throws EmptyException{
        if(totalSalary == 0 ){
            throw new EmptyException("工资总额为0时，抛出空异常");
        }
        System.out.println("员工工资总额："+ totalSalary);
    }
    /**
     * 显示员工人数：void showTotalEmployee（），抛出空异常。当员工人数为0时，抛出此异常。
     */
    public static void showTotalEmployee() throws EmptyException{
        if(totalEmployees == 0 ){
            throw new EmptyException("员工人数为0时，抛出空异常");
        }
        System.out.println("员工人数："+ totalEmployees);
    }
}
